package com.lxl.todo;
/**
*
* 给定一个整数数组 nums，轮转数组将数组中的元素向右轮转 k 个位置，其中 k 是非负数。
* 输入: nums = [1,2,3,4,5,6,7], k = 3
* 5 2 3 1 4 6 7
* 5 6 3 1 2
*
输出: [5,6,7,1,2,3,4]
*
* */
public class Solution14 {
    public void rotate(int[] nums, int k) {
        k %= nums.length;
        reverse(nums, 0, nums.length - 1);
        reverse(nums, 0, k - 1);
        reverse(nums, k, nums.length - 1);
    }

    public void reverse(int[] nums, int start, int end) {
        while (start < end) {
            int temp = nums[start];
            nums[start] = nums[end];
            nums[end] = temp;
            start++;
            end--;
        }
    }
    public static void main(String[] args) {
        int[] nums = {1,2};
        Solution14 solution = new Solution14();
        solution.rotate(nums,7);
        solution.reverse(nums,0,nums.length-1);
    }
}
